package com.repair.project.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.repair.project.config.R;
import com.repair.project.entity.Announce;
import com.repair.project.entity.Cycle;
import com.repair.project.service.AnnounceService;
import com.repair.project.service.CycleService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hz
 * @since 2021-01-12
 */
@RestController
@RequestMapping("/project/announce")
public class AnnounceController {
    @Autowired
    AnnounceService announceService;

    @ApiOperation("接口描述：获取公告")
    @GetMapping("getAncList")
    public R getAncList(@RequestParam(value = "page")int page, @RequestParam(value = "limit")int limit,
                          @RequestParam(required = false, value = "statu")String statu,
                        @RequestParam(required = false, value = "announceid")Integer announceid){

        List<Announce> announce =announceService.list(null);
        Page<Announce> announcePage = new Page<>(page, limit);

        QueryWrapper<Announce> objectQueryWrapper = new QueryWrapper<>();
        if(statu!=null && statu!="") {
            objectQueryWrapper.eq("statu", statu);
        }
        if(announceid!=null) {
            objectQueryWrapper.eq("announceid", announceid);
        }
        IPage<Announce> announceIPage = announceService.page(announcePage, objectQueryWrapper);
        return R.ok().data("datalist",announceIPage);
    }

    @ApiOperation("接口描述:增加公告")
    @PostMapping("addAnc")
    public R addAnc(@RequestBody Announce announce){
        return R.ok().data("data",announceService.save(announce));
    }

    @ApiOperation("接口描述：删除公告")
    @GetMapping("delAnc")
    public R delAnc(@RequestParam(value = "announceid")int announceid){
        return R.ok().data("data",announceService.removeById(announceid));
    }

    @ApiOperation("接口描述：更新公告")
    @PostMapping("updAnc")
    public R updAnc(@RequestBody Announce announce){
        return R.ok().data("data",announceService.updateById(announce));
    }





}

